;; The first four lines of this file were added by Dracula.
;; They tell DrScheme that this is a Dracula Modular ACL2 program.
;; Leave these lines unchanged so that DrScheme can properly load this file.
#reader(planet "reader.rkt" ("cce" "dracula.plt") "modular" "lang")
(require "iHueChange.lisp")
(require "icommon.lisp")
(require "iimage.lisp")

(module MHueChange
  (include-book "avl-rational-keys" :dir :teachpacks)
  (include-book "io-utilities" :dir :teachpacks)
  (import IImage)
  (import ICommon)
  
  (defun pixel-to-hue-original (r g b h)
    (if (and (<= r 255) (>= r 0)
             (<= g 255) (>= g 0)
             (<= b 255) (>= b 0)
             (<= h 360) (>= h 0))
        (let* ((hsv (RGB-to-HSV r g b))
               (s   (cadr hsv))
               (v   (caddr hsv)))
          (HSV-to-RGB h s v))
        "Invalid RGB value."))
  
  (defun HueChangePixel (tree hue x y width height)
    (let* ((nextX (getNextXCoordinate x width))
           (nextY (getNextYCoordinate x y width))
           (pixel (getPixel tree x y)))
      (let* ((r        (car pixel))
             (g        (cadr pixel))
             (b        (caddr pixel))
             (newColor (pixel-to-hue-original r g b hue)))
        (if (isValidPixel nextX nextY width height)
            (HueChangePixel (insertPixelAsRGBList tree x y newColor) hue nextX nextY width height)
            (insertPixelAsRGBList tree x y newColor)))))
  
  (defun MainHueChange(tree args)
    (let* ((hue (str->rat(car args)))
           (Width  (getWidth tree))
           (Height (getHeight tree)))
          (mv (HueChangePixel tree hue 1 Height Width Height) (list "Sucessfully changed the hue of the image."))))
  
  
  (export IHueChange))